package main.servlet;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import main.dao.UserDao;
import main.dao.impl.UserDaoImpl;
import main.pojo.User;

/**
 * Servlet implementation class ImageServlet
 */
public class ImageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		///加载图片
		String uname = request.getParameter("uname");
		UserDao userDao = new UserDaoImpl();
		User user = userDao.searchUser(uname);
		response.setHeader("Content-Type", "image/jpeg");
		OutputStream out = response.getOutputStream();
		out.write(user.getHeadPic());
		out.close();
	}

}
